<template>
  <div class="today-info">
    <h1>{{ welcome_word }}</h1>
    <span>{{ today_date }}</span>
    <el-row>
      <el-col :span="6">
        <div class="situation">
          <div class="icon">
            <i class="iconfont icon-clock" />
          </div>
          <div>
            <div class="title">待接单</div>
            <div class="data">{{ order_data.pending }}</div>
          </div>
        </div>
      </el-col>
      <el-col :span="6">
        <div class="situation">
          <div class="icon">
            <i class="iconfont icon-ongoing" />
          </div>
          <div>
            <div class="title">进行中</div>
            <div class="data">{{ order_data.ongoing }}</div>
          </div>
        </div>
      </el-col>
      <el-col :span="6">
        <div class="situation">
          <div class="icon">
            <i class="iconfont icon-finished" />
          </div>
          <div>
            <div class="title">已完成</div>
            <div class="data">{{ order_data.completed }}</div>
          </div>
        </div>
      </el-col>
      <el-col :span="6">
        <img src="/home/today_info.png" alt="今日信息" />
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
// 首页欢迎语
const welcome_word = ref('')
// 当日日期
const today_date = ref('')
onMounted(() => {
  welcome_word.value = getWelcomeWord()
  formatDate()
})
// 获取当天订单数据
const order_data = ref({
  pending: 35,
  ongoing: 20,
  completed: 15
})
// 根据当前时间生成欢迎语
const getWelcomeWord = () => {
  const hour = new Date().getHours()
  if (hour < 6) {
    return 'It is late at night, go to bed early!'
  } else if (hour < 12) {
    return 'Good morning, have a nice day!'
  } else if (hour < 14) {
    return 'Good noon, enjoy your lunch and lunch break!'
  } else if (hour < 18) {
    return 'Good afternoon, have a productive day!'
  } else {
    return 'Good evening, it is time to relax!'
  }
}
// 格式化当前日期
const formatDate = () => {
  const date = new Date()
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  today_date.value = `${year}年${month}月${day}日`
}
</script>

<style scoped lang="scss">
.today-info {
  position: relative;
  width: 100%;
  color: #fff;
  background-color: #8c91f4;
  border-radius: 16px;
  padding: 2.5vh 2vw;

  h1 {
    font-size: 24px;
    font-weight: bold;
  }

  span {
    font-weight: bold;
  }

  .situation {
    margin-top: 2vh;
    display: flex;

    .icon {
      width: 4vmax;
      height: 4vmax;
      text-align: center;
      line-height: 4vmax;
      border-radius: 12px;
      background-color: rgba(255, 255, 255, 0.4);
      margin-right: 16px;
    }

    .iconfont {
      font-size: 4vmin;
    }

    .title {
      font-size: 16px;
    }

    .data {
      font-size: 26px;
      font-weight: bold;
    }
  }
  img {
    position: absolute;
    right: 6vw;
    bottom: 0;
    width: 12vw;
  }
}
</style>
